package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.model.BaseAttrInfo;
import com.atguigu.gmall.product.model.BaseAttrValue;
import com.atguigu.gmall.product.service.BaseAttrInfoService;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: atguigu
 * @create: 2022-12-23 14:45
 */
@RestController
@RequestMapping("/admin/product")
//@CrossOrigin
public class BaseAttrInfoController {

    @Autowired
    private BaseAttrInfoService baseAttrInfoService;


    /**
     * 新增平台属性包含属性值，关联到某个分类下
     * ctrl+alt+b直接定位到方法实现
     * @param baseAttrInfo
     * @return
     */
    @PostMapping("/saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo) {
        baseAttrInfoService.saveAttrInfo(baseAttrInfo);
        return Result.ok();
    }


    /**
     * 根据平台属性Id 获取到平台属性值集合
     * @param attrId
     * @return
     */
    @GetMapping("/getAttrValueList/{attrId}")
    public Result<List<BaseAttrValue>> getAttrValueList(@PathVariable("attrId") Long attrId){
        List<BaseAttrValue> list = baseAttrInfoService.getAttrValueList(attrId);
        return Result.ok(list);
    }
}
